import 'dart:async';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_app/Utils/Constants.dart';
import 'dart:convert';
import 'package:crypto/crypto.dart';

/*
 *  登录前接口
 */

Map<String, String> verifyIP(String type) {
  Map<String, String> map = new Map();
  map['type'] = type;
  return map;
}

Future<Map<String, String>> baseRequest() async {
  Map<String, String> map = new Map();
  SharedPreferences _prefs = await SharedPreferences.getInstance();
  map['ClientId'] = _prefs.getString(Constants.clientId);
  map['ClientName'] = _prefs.getString(Constants.clientName);
  map['OperatorId'] = _prefs.getString(Constants.operatorId) ?? '';
  map['OperatorName'] = _prefs.getString(Constants.operatorName) ?? '';
  return map;
}

Future<Map<String, String>> verifyRegister() async {
  Map<String, String> map = await baseRequest();
  map['Required'] = '';
  map['Type'] = '128';
  print(map);
  return map;
}

Future<Map<String, String>> registMobile(
    String sourceType, String bindUser) async {
  Map<String, String> map = await baseRequest();
  map['Phone'] = '';
  map['SourceType'] = sourceType;
  map['BindUser'] = bindUser;
  map['Type'] = '301';
  print(map);
  return map;
}

Future<Map<String, String>> login(String password) async {
  Map<String, String> map = await baseRequest();
  String base64ePwd = base64.encode(utf8.encode(password));
  map['Required'] = 'DLMM=' + base64ePwd + '&DYLX=1';
  map['Type'] = '129';
  print(map);
  return map;
}
